<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>私有属性</title>
  </head>
  <body>
    <script>
      class Person {
        // 公有属性
        name;
        // 私有属性
        #age;
        #weight;
        // 构造方法
        constructor(name, age, weight) {
          this.name = name;
          this.#age = age;
          this.#weight = weight;
        }
        intro(){
          console.log(this.name);
          console.log(this.#age);
          console.log(this.#weight);
        }
      }

      // 实例化
      const girl = new Person("小红",18,"50kg");
      console.log(girl);

      console.log(girl.name);
      // console.log(girl.#age); 私有属性在类的外部能直接访问
      girl.intro(); // 通过在类的内部封装方法进行访问
      </script>
  </body>
</html>
